﻿using MediatR;
using NationalD3.Domain.Events;
using System.Threading;
using System.Threading.Tasks;
using NationalD3.Domain.Interfaces;

namespace NationalD3.Domain.EventHandlers
{
    /// <summary>
    /// Student事件处理程序
    /// 继承INotificationHandler<T>，可以同时处理多个不同的事件模型
    /// </summary>
    public class StudentEventHandler : INotificationHandler<StudentRegisteredEvent>
    {
        private readonly IShortMessage _sms;

        public StudentEventHandler(IShortMessage sms)
        {
            _sms = sms;
        }
        /// <summary>
        /// 学生被注册成功后的事件处理方法
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task Handle(StudentRegisteredEvent notification, CancellationToken cancellationToken)
        {
            // 恭喜您，注册成功，欢迎加入我们。
            
            //在此处发送短信通知用于注册成功
            _sms.Send(notification.Phone, notification.Name);

            return Task.CompletedTask;
        }

    }
}